<cfinclude template="/code_lib/SCF_HR.cfm" />
<cfinclude template="/code_lib/SCF_Employee.cfm" />

<cfldap action="QUERY" name="ldapUsers" server="10.100.1.9"
	attributes="cn,sAMAccountName,mDBStorageQuota"
	start="OU=SCFUsers,dc=SouthcentralFoundation,dc=com"
	filter="(&(!(OU=Archived_Users))(mDBStorageQuota=*)(mail=*))"
	sort="displayName"
	username="scf\Userlist"
	password="DefinedMan" />
	
<cfset usr_total = 0 />
<cfset org_total = 0 />
<cfset new_total = 0 />

<html>
	<head>
		<title>Mailbox Size Updater</title>
		<style type="text/css">
			th { text-align: left; }
		</style>
	</head>
	<body>
		<table>
			<tr>
				<th>Name</th>
				<th>Old Mail Quota</th>
				<th>New Mail Quota</th>
				<th>Net Change</th>
			</tr>
			<cfloop query="ldapUsers">
			<cfquery name="qryRosetta" datasource="RosettaStone">
				SELECT RosettaID
				FROM RosettaStone
				WHERE UserAccount = <cfqueryparam value="#sAMAccountName#" /> 
			</cfquery>
			
			<!--- Figure proper size --->
			<cfset newsize = 262144 />
			
			<cfif qryRosetta.RecordCount gt 0>
				<!--- These have to be in this order, in that a director is a supervisor --->
				<cfif SCF_HR_IsEmployeeADirector(qryRosetta.RosettaID[1])>
					<cfset newsize = 1048576 />
				<cfelseif SCF_HR_IsEmployeeASupervisor(qryRosetta.RosettaID[1])>
					<cfset newsize = 524288 />
				</cfif>
			</cfif>
			
			<cfif newsize gt mDBStorageQuota>
				<cfset usr_total++ />
				<cfset org_total += mDBStorageQuota />
				<cfset new_total += newsize />

				<cfoutput>
					<tr>
						<td>#cn#</td>
						<td>#mDBStorageQuota / 1024#MB</td>
						<td>#newsize / 1024#MB</td>
						<td>#(newsize - mDBStorageQuota) / 1024#MB</td>
					</tr>
				</cfoutput>
			</cfif>
			</cfloop>
			<cfoutput>
			<th>#usr_total# users to change</th>
			<th>#org_total / 1024#MB</th>
			<th>#new_total / 1024#MB</th>
			<th>#(new_total - org_total) / 1024#MB</th>
			</cfoutput>
		</table>
	</body>
</html>